package com.devshephard.jucks.countDown.countDownLunch;

import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;

public class countDownLunchOnly {

    public static void main(String[] args) throws InterruptedException {

        //定义一个线程减法计数器，计数数量为6
        CountDownLatch countDownLatch = new CountDownLatch(3);

        Thread t1 = new Thread(()->{
            System.out.println("t1 Go");
            countDownLatch.countDown();
        });
        t1.start();

        Thread t2 = new Thread(()->{
            System.out.println("t2 Go");
            countDownLatch.countDown();
        });
        t2.start();

        Thread t3 = new Thread(()->{
            System.out.println("t3 Go");
            countDownLatch.countDown();
        });
        t3.start();


        //当所有线程执行完毕后，在走下一步
        countDownLatch.await(5, TimeUnit.SECONDS);
        //countDownLatch.await();

        System.out.println("线程执行完毕，当前数量：" + countDownLatch.getCount());

    }

}
